| Conditions | 4 |
| Paths | 2049 |
| Total Lines | 96 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | // Copyright © 2017 Tangdongxin |
||
| 25 | function onConfig(result) { |
||
| 26 | if (!result) { |
||
| 27 | console.log("No Config find"); |
||
|
|
|||
| 28 | fontStyle = "Consolas"; |
||
| 29 | fontSize = "14px"; |
||
| 30 | bgColor = "#FDF6E3"; |
||
| 31 | intColor = "#657A81"; |
||
| 32 | strColor = "#2AA198"; |
||
| 33 | keyColor = "#B58900"; |
||
| 34 | defaultColor = "#586E75"; |
||
| 35 | |||
| 36 | strictOnly = false; |
||
| 37 | hideDetails = false; |
||
| 38 | dontBeatify = false; |
||
| 39 | return; |
||
| 40 | } |
||
| 41 | if (result && result[0]) { |
||
| 42 | fontStyle = result[0].fontStyle || "Consolas"; |
||
| 43 | fontSize = result[0].fontSize || "14px"; |
||
| 44 | bgColor = result[0].bgColor || "#FDF6E3"; |
||
| 45 | intColor = result[0].intColor || "#657A81"; |
||
| 46 | strColor = result[0].strColor || "#2AA198"; |
||
| 47 | keyColor = result[0].keyColor || "#B58900"; |
||
| 48 | defaultColor = result[0].defaultColor || "#586E75"; |
||
| 49 | |||
| 50 | strictOnly = result[0].strictOnly || false; |
||
| 51 | hideDetails = result[0].hideDetails || false; |
||
| 52 | dontBeatify = result[0].dontBeatify || false; |
||
| 53 | } else { |
||
| 54 | fontStyle = result.fontStyle || "Consolas"; |
||
| 55 | fontSize = result.fontSize || "14px"; |
||
| 56 | bgColor = result.bgColor || "#FDF6E3"; |
||
| 57 | intColor = result.intColor || "#657A81"; |
||
| 58 | strColor = result.strColor || "#2AA198"; |
||
| 59 | keyColor = result.keyColor || "#B58900"; |
||
| 60 | defaultColor = result.defaultColor || "#586E75"; |
||
| 61 | |||
| 62 | strictOnly = result.strictOnly || false; |
||
| 63 | hideDetails = result.hideDetails || false; |
||
| 64 | dontBeatify = result.dontBeatify || false; |
||
| 65 | } |
||
| 66 | |||
| 67 | document.addEventListener("click", function(e) { |
||
| 68 | console.log(e); |
||
| 69 | var target = e.target; |
||
| 70 | if (target.tagName.toUpperCase() == "I") { |
||
| 71 | var isClose = target.classList.contains(COLL); |
||
| 72 | console.log(isClose); |
||
| 73 | var classname = target.classList[0]; |
||
| 74 | console.log(classname); |
||
| 75 | if (isClose) { |
||
| 76 | target.removeAttribute("class"); |
||
| 77 | target.setAttribute("class", classname); |
||
| 78 | } else { |
||
| 79 | target.removeAttribute("class"); |
||
| 80 | target.setAttribute("class", classname + " C" + classname.substring(1)); |
||
| 81 | } |
||
| 82 | e.preventDefault(); |
||
| 83 | } else if (target.tagName.toUpperCase() == "STR") { |
||
| 84 | var parentElement = target.parentElement; |
||
| 85 | var originStr = parentElement.innerHTML; |
||
| 86 | parentElement.innerHTML = parentElement.getAttribute("content"); |
||
| 87 | parentElement.setAttribute("content", originStr); |
||
| 88 | } else if (target.tagName.toUpperCase() == "JSON") { |
||
| 89 | if (document.getElementById("light")) { |
||
| 90 | var lightDiv = document.getElementById("light"); |
||
| 91 | lightDiv.parentElement.removeChild(lightDiv); |
||
| 92 | } |
||
| 93 | if (document.getElementById("fade")) { |
||
| 94 | var fadeDiv = document.getElementById("fade"); |
||
| 95 | fadeDiv.parentElement.removeChild(fadeDiv); |
||
| 96 | } |
||
| 97 | |||
| 98 | var parentElement = target.parentElement; |
||
| 99 | |||
| 100 | var fadeDiv = document.createElement("div"); |
||
| 101 | fadeDiv.setAttribute("id", "fade"); |
||
| 102 | fadeDiv.classList.add("black_overlay"); |
||
| 103 | document.body.appendChild(fadeDiv); |
||
| 104 | |||
| 105 | var lightDiv = document.createElement("div"); |
||
| 106 | lightDiv.setAttribute("id", "light"); |
||
| 107 | lightDiv.classList.add("white_content"); |
||
| 108 | document.body.appendChild(lightDiv); |
||
| 109 | |||
| 110 | document.getElementById('light').style.display = 'block'; |
||
| 111 | document.getElementById('fade').style.display = 'block'; |
||
| 112 | draw(eval(parentElement.getAttribute("json")), lightDiv); |
||
| 113 | } else if (target.classList.contains("black_overlay")) { |
||
| 114 | var fadeDiv = document.getElementById("fade"); |
||
| 115 | fadeDiv.parentElement.removeChild(fadeDiv); |
||
| 116 | var lightDiv = document.getElementById("light"); |
||
| 117 | lightDiv.parentElement.removeChild(lightDiv); |
||
| 118 | } |
||
| 119 | }, true); |
||
| 120 | } |
||
| 121 | |||
| 122 |